/**
 * 数据请求相关
 */
const baseURL = 'https://api-hmugo-web.itheima.net'
// const baseURL = 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata'
/**
 * 首页轮播图 
 */
export const bannerList = () => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/api/public/v1/home/swiperdata`,
      method: 'GET',
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}

/**
 * 首页导航菜单
 */
export const homeCate = () => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/api/public/v1/home/catitems`,
      method: 'GET',
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}

/**
 * 首页楼层
 */
export const homeFloor = () => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/api/public/v1/home/floordata`,
      method: 'GET',
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}

/**
 * 分类页菜单数据
 */
export const categoryMenu = () => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/api/public/v1/categories`,
      method: 'GET',
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}

/**
 * 商品列表页数据
 */
export const goodsList = params => {
  return new Promise((resolve,reject) => {
    uni.request({
      // ...params,
      url: `${baseURL}/api/public/v1/goods/search`,
      method: 'GET',
      data: {
        query: params.query,
        cid: params.cid,
        pagenum: params.pagenum,
        pagesize: params.pagesize
      },
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}

/**
 * 商品详情页数据
 */
export const goodsDetail = id => {
  return new Promise((resolve,reject) => {
    uni.request({
      // ...params,
      url: `${baseURL}/api/public/v1/goods/detail`,
      method: 'GET',
      data: {
        goods_id: id
      },
      success: res => {
        resolve(res)
        uni.hideToast()
      }
    })
  })
}